package _17_lianxi;

import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class Case {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		SortedSet cases = new TreeSet(new Comparator() {

			// 匿名内部类实现
			@Override
			public int compare(Object o1, Object o2) {
				// o1是要添加的元素
				// o2是集合中的元素
				int number1 = ((Case1) o1).number;
				int number2 = ((Case1) o2).number;
				int id1 = ((Case1) o1).idNumber;
				int id2 = ((Case1) o2).idNumber;
				if (id1 == id2) {
					return 0;
				} else {
					if (number1 == number2) {
						return 0;
					} else if (number1 < number2) {
						return -1;
					} else {
						return 1;
					}
				}
			}

		});
		Case1 c1 = new Case1(004, 123456, "张三");
		Case1 c2 = new Case1(005, 123434, "李四");
		Case1 c3 = new Case1(003, 123456, "张三");
		Case1 c4 = new Case1(001, 423223, "王五");
		Case1 c5 = new Case1(002, 543342, "赵六");
		cases.add(c1);
		cases.add(c2);
		cases.add(c3);
		cases.add(c4);
		cases.add(c5);
		for (Object object : cases) {
			System.out.println(object);
		}
	}

}

class Case1 {
	int number;
	int idNumber;
	String name;

	public Case1(int number, int idNumber, String name) {
		super();
		this.number = number;
		this.idNumber = idNumber;
		this.name = name;
	}

	@Override
	public String toString() {
		return "Case1 [number=" + number + ", idNumber=" + idNumber + ", name=" + name + "]";
	}

}